using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for LibrariesAdaptor.
	/// </summary>
	public class LibrariesAdaptor : Adaptor, IRefreshable
	{
    private LibraryCollection libs;
    public LibrariesAdaptor(LibraryCollection libs)
    {
      this.libs = libs;
    }

    public override void AddChildren(TreeNode node)
    {
      foreach (Library lib in libs)
      {
        TreeNode libNode = TreeNodeFactory.CreateTreeNode(new LibraryAdaptor(lib));
        node.Nodes.Add(libNode);
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 7;
      }
    }

    public override string Text
    {
      get
      {
        return "Libraries (" + libs.Count + ")";
      }
    }

    public override Control GetRenderer()
    {
      LibrariesControl control = new LibrariesControl();
      control.LoadLibraries(libs);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    public override object Object
    {
      get
      {
        return libs;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      libs.Refresh();
    }

    #endregion
  }
}
